package com.hcs.chenyu.chenyuusedmarket;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.hcs.chenyu.R;
import com.hcs.chenyu.library.books;
import com.hcs.chenyu.yongpin;

public class usedmarket extends AppCompatActivity {

    //需要适配的数据
    private String[] titles = { "桌子", "水果", "蔬菜", "电子产品", "衣服",
            "球类", "轮滑", "平时用品", "食品",
            "书籍","鞋", "玩具", "卡类"};
    private String[] prices = { "1元以上", "1元/kg以上", "1元/kg以上", "1元以上", "1元以上",
            "1元以上", "30元以上", "10元以上", "0.5元以上",
            "1元以上","10元以上", "1元以上", "1元以上"};
    //图片集合
    private int[] icons = {R.drawable.table,R.drawable.guolan,R.drawable.vegetable,
            R.drawable.iphone,R.drawable.wireclothes,R.drawable.basketball,
            R.drawable.lunhua, R.drawable.pen,R.drawable.kiwifruit,R.drawable.shu,
            R.drawable.lanqiuxie,R.drawable.wanju,R.drawable.ka};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_usedmarket);
        ListView mListView = findViewById(R.id.list_view);
        myBaseAdapter adapter = new myBaseAdapter();
        mListView.setAdapter(adapter);


        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @SuppressLint("ResourceType")
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                System.out.println(position);
                switch (position){
                    case 0:
                        Intent intent = new Intent(usedmarket.this, usedmarkettable.class);
                        startActivity(intent);
                        break;
                    case 1:
                        Intent intent1 = new Intent(usedmarket.this, usedmarketfriut.class);
                        startActivity(intent1);
                        break;
                    case 2:
                        Intent intent2 = new Intent(usedmarket.this, vegetables.class);
                        startActivity(intent2);
                        break;
                    case 3:
                        Intent intent3 = new Intent(usedmarket.this, eletronct.class);
                        startActivity(intent3);
                        break;
                    case 4:
                        Intent intent4 = new Intent(usedmarket.this, clothes.class);
                        startActivity(intent4);
                        break;
                    case 5:
                        Intent intent5 = new Intent(usedmarket.this, balls.class);
                        startActivity(intent5);
                        break;
                    case 6:
                        Intent intent6 = new Intent(usedmarket.this, lunhua.class);
                        startActivity(intent6);
                        break;
                    case 7:
                        Intent intent7 = new Intent(usedmarket.this, yongpin.class);
                        startActivity(intent7);
                        break;
                    case 8:
                        Intent intent8 = new Intent(usedmarket.this, food.class);
                        startActivity(intent8);
                        break;
                    case 9:
                        Intent intent9 = new Intent(usedmarket.this, books.class);
                        startActivity(intent9);
                        break;
                    case 10:
                        Intent intent10 = new Intent(usedmarket.this, shoes.class);
                        startActivity(intent10);
                        break;
                    case 11:
                        Intent intent11 = new Intent(usedmarket.this, cards.class);
                        startActivity(intent11);
                        break;

                }

            }
        });
    }

    class myBaseAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public Object getItem(int position) {
            return titles[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            View view = View.inflate(usedmarket.this, R.layout.listviewbujv, null);
            ImageView iv = view.findViewById(R.id.iv);
            TextView title = view.findViewById(R.id.title);
            TextView price = view.findViewById(R.id.price);

            iv.setBackgroundResource(icons[position]);
            title.setText(titles[position]);
            price.setText(prices[position]);

            return view;
        }
    }


}
